package com.game.hall;

import com.game.net.server.http.HttpServer;
import com.game.net.server.http.HttpServerHandler;
import com.game.net.server.jpbsocket.JPbSocketNettyServer;
import com.game.common.QueueEventThread;
import com.game.net.server.websocket.WebSocketNettyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Created by legend9999 on 2016/4/23.
 */
@Component
public class HallMain {
    private static Logger logger = LoggerFactory.getLogger(HallMain.class);

    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        GameServerConnectManager bean = ac.getBean(GameServerConnectManager.class);
        //bean.connect();
        startHttpServer(ac);
        new Thread(ac.getBean(QueueEventThread.class)).start();
        boolean isWS = true;
        if (isWS) {
            HallWSHandler hallWSHandler = ac.getBean(HallWSHandler.class);
            WebSocketNettyServer webSocketNettyServer = ac.getBean(WebSocketNettyServer.class);
            webSocketNettyServer.init(8080, hallWSHandler);
        } else {
            HallJPBHandler hallJPBHandler = ac.getBean(HallJPBHandler.class);
            JPbSocketNettyServer jPbSocketNettyServer = ac.getBean(JPbSocketNettyServer.class);
            jPbSocketNettyServer.init(9001, hallJPBHandler);
        }
    }


    public static void startHttpServer(ApplicationContext ac) {
        HttpServer httpServer = ac.getBean(HttpServer.class);
        httpServer.init(8081, null);
    }

}
